package com.assessment.servermanager.service.impl;

import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import cn.hutool.core.util.ObjectUtil;
import com.assessment.servermanager.commen.entity.PageQuery;
import com.assessment.servermanager.commen.page.TableDataInfo;
import com.assessment.servermanager.commen.utils.StringUtils;
import com.assessment.servermanager.entity.TbSign;
import com.assessment.servermanager.entity.bo.TbSignBo;
import com.assessment.servermanager.entity.vo.TbSignVo;
import com.assessment.servermanager.mapper.TbSignMapper;
import com.assessment.servermanager.service.ITbSignService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


/**
 * 【请填写功能名称】Service业务层处理
 *
 * @author jiajia
 * @date 2023-08-28
 */
@Service
public class TbSignServiceImpl implements ITbSignService {
    @Autowired
    private TbSignMapper tbSignMapper;

    /**
     * 查询【请填写功能名称】
     *
     * @param id 【请填写功能名称】主键
     * @return 【请填写功能名称】
     */
    @Override
    public TbSign selectTbSignById(Long id) {
        return tbSignMapper.selectById(id);
    }

    /**
     * 查询【请填写功能名称】列表
     *
     * @param tbSignBo 【请填写功能名称】
     * @return 【请填写功能名称】
     */
    @Override
    public TableDataInfo<TbSignVo> selectTbSignList(TbSignBo tbSignBo, PageQuery pageQuery) {
        QueryWrapper<TbSign> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(tbSignBo.getFlag() != null,"sign.flag", tbSignBo.getFlag());
        queryWrapper.eq(tbSignBo.getEid() != null,"sign.eid", tbSignBo.getEid());
        queryWrapper.eq(StringUtils.isNotEmpty(tbSignBo.getLocation()),"sign.location", tbSignBo.getLocation());
        queryWrapper.apply(ObjectUtil.isNotNull(tbSignBo.getCreateTime()),"createTime" + tbSignBo.getStartTime()+"and"+ tbSignBo.getEndTime());
        queryWrapper.eq("exam.delFlag",0);
        Page<TbSignVo> page = tbSignMapper.selectPageSignList(pageQuery.build(),queryWrapper);
        return TableDataInfo.build(page);
    }

    /**
     * 新增【请填写功能名称】
     *
     * @param tbSign 【请填写功能名称】
     * @return 结果
     */
    @Override
    public int insertTbSign(TbSign tbSign) {
        tbSign.setCreateTime(new Date());
        return tbSignMapper.insert(tbSign);
    }

    /**
     * 修改【请填写功能名称】
     *
     * @param tbSign 【请填写功能名称】
     * @return 结果
     */
    @Override
    public int updateTbSign(TbSign tbSign) {
        return tbSignMapper.updateById(tbSign);
    }

    /**
     * 批量删除【请填写功能名称】
     *
     * @param ids 需要删除的【请填写功能名称】主键
     * @return 结果
     */
    @Override
    public int deleteTbSignByIds(Long[] ids) {
        return tbSignMapper.deleteBatchIds(Arrays.stream(ids).collect(Collectors.toList()));
    }

    /**
     * 删除【请填写功能名称】信息
     *
     * @param id 【请填写功能名称】主键
     * @return 结果
     */
    @Override
    public int deleteTbSignById(Long id) {
        return tbSignMapper.deleteById(id);
    }

    @Override
    public List<Map<String, Object>> signTotalCount(Integer years,Integer month) {
        return tbSignMapper.signTotalCount(years,month);
    }
}
